﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Forms;

namespace ImaginationFactory.Dialogs
{
    /// <summary>
    /// CutOutDialog.xaml 的交互逻辑
    /// </summary>
    public partial class CutOutDialog : Window
    {
        static MainWindow mWindowTemp;
        //static MainListBox mListBox;
        static int xCutOutTemp1;
        static int xCutOutTemp2;
        static int yCutOutTemp1;
        static int yCutOutTemp2;

        public CutOutDialog( MainWindow mWindow)
        {
            InitializeComponent();
            mWindowTemp = mWindow;

            xCutOut1.Text = "0";
            yCutOut1.Text = "0";
            xCutOut2.Text = mWindowTemp.ImageLibrary.Width.ToString();
            yCutOut2.Text = mWindowTemp.ImageLibrary.Height.ToString();
        }

        private void xCutOut1_TextChanged(object sender, TextChangedEventArgs e)
        {
            //判断坐标合理性
            if ( Convert.ToInt32(xCutOut1.Text)>=0 )
            {
                xCutOutTemp1 = Convert.ToInt32(xCutOut1.Text);
                
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("请输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                
            } 
        }

        private void yCutOut1_TextChanged(object sender, TextChangedEventArgs e)
        {
            //判断坐标合理性
            if (Convert.ToInt32(yCutOut1.Text) >= 0)
            {
                yCutOutTemp1 = Convert.ToInt32(yCutOut1.Text);

            }
            else
            {
                System.Windows.Forms.MessageBox.Show("请输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

            } 
        }

        private void xCutOut2_TextChanged(object sender, TextChangedEventArgs e)
        {
            //判断坐标合理性
            if (Convert.ToInt32(xCutOut2.Text) >= 0)
            {
                xCutOutTemp2 = Convert.ToInt32(xCutOut2.Text);

            }
            else
            {
                System.Windows.Forms.MessageBox.Show("请输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

            } 
        }

        private void yCutOut2_TextChanged(object sender, TextChangedEventArgs e)
        {
            //判断坐标合理性
            if (Convert.ToInt32(yCutOut2.Text) >= 0)
            {
                yCutOutTemp2 = Convert.ToInt32(yCutOut2.Text);

            }
            else
            {
                System.Windows.Forms.MessageBox.Show("请输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

            } 
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            mWindowTemp.ImageLibrary.CutOutImage(new Point(xCutOutTemp1, yCutOutTemp1), new Point(xCutOutTemp2, yCutOutTemp2));
            mWindowTemp.image.Source = mWindowTemp.ImageLibrary.LoadedImage.Source;
            //mListBox.cutOutItem.IsSelected = false;
            this.Close();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //mListBox.cutOutItem.IsSelected = false;
            this.Close();
        }

        private void ImageSizeDlg_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }
    }
}
